home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / system / shaders / convolution-4x4_d3d.fx next >
Encoding:
Text File  |  2011-03-08  |  2.9 KB  |  116 lines

  1. /*
  2.  *      Copyright (C) 2005-2010 Team XBMC
  3.  *      http://www.xbmc.org
  4.  *
  5.  *  This Program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2, or (at your option)
  8.  *  any later version.
  9.  *
  10.  *  This Program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with XBMC; see the file COPYING.  If not, write to
  17.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *  http://www.gnu.org/copyleft/gpl.html
  19.  *
  20.  */
  21.  
  22. texture g_Texture;
  23. texture g_KernelTexture;
  24. float2  g_StepXY;
  25.  
  26. sampler RGBSampler =
  27.   sampler_state {
  28.     Texture = <g_Texture>;
  29.     AddressU = CLAMP;
  30.     AddressV = CLAMP;
  31.     MipFilter = LINEAR;
  32.     MinFilter = POINT;
  33.     MagFilter = POINT;
  34.   };
  35.  
  36. sampler KernelSampler =
  37.   sampler_state
  38.   {
  39.     Texture = <g_KernelTexture>;
  40.     AddressU = CLAMP;
  41.     AddressV = CLAMP;
  42.     MipFilter = LINEAR;
  43.     MinFilter = LINEAR;
  44.     MagFilter = LINEAR;
  45.   };
  46.  
  47. struct VS_OUTPUT
  48. {
  49.   float4 Position   : POSITION;
  50.   float2 TextureUV  : TEXCOORD0;
  51. };
  52.  
  53. struct PS_OUTPUT
  54. {
  55.   float4 RGBColor : COLOR0;
  56. };
  57.  
  58. half4 weight(float pos)
  59. {
  60.   return tex1D(KernelSampler, pos);
  61. }
  62.  
  63. half3 pixel(float xpos, float ypos)
  64. {
  65.   return tex2D(RGBSampler, float2(xpos, ypos)).rgb;
  66. }
  67.  
  68. half3 getLine(float ypos, float4 xpos, half4 linetaps)
  69. {
  70.   return
  71.     pixel(xpos.r, ypos) * linetaps.r +
  72.     pixel(xpos.g, ypos) * linetaps.g +
  73.     pixel(xpos.b, ypos) * linetaps.b +
  74.     pixel(xpos.a, ypos) * linetaps.a;
  75. }
  76.  
  77. PS_OUTPUT CONVOLUTION4x4(VS_OUTPUT In)
  78. {
  79.   PS_OUTPUT OUT;
  80.  
  81.   float2 pos = In.TextureUV + g_StepXY * 0.5;
  82.   float2 f = frac(pos / g_StepXY);
  83.  
  84.   half4 linetaps   = weight(1.0 - f.x);
  85.   half4 columntaps = weight(1.0 - f.y);
  86.  
  87.   // kernel generation code made sure taps add up to 1, no need to adjust here.
  88.  
  89.   float2 xystart = (-1.0 - f) * g_StepXY + In.TextureUV;
  90.   float4 xpos = float4(
  91.       xystart.x,
  92.       xystart.x + g_StepXY.x,
  93.       xystart.x + g_StepXY.x * 2.0,
  94.       xystart.x + g_StepXY.x * 3.0);
  95.  
  96.   OUT.RGBColor.rgb =
  97.     getLine(xystart.y                   , xpos, linetaps) * columntaps.r +
  98.     getLine(xystart.y + g_StepXY.y      , xpos, linetaps) * columntaps.g +
  99.     getLine(xystart.y + g_StepXY.y * 2.0, xpos, linetaps) * columntaps.b +
  100.     getLine(xystart.y + g_StepXY.y * 3.0, xpos, linetaps) * columntaps.a;
  101.  
  102.   OUT.RGBColor.a = 1.0;
  103.   return OUT;
  104. }
  105.  
  106. technique SCALER_T
  107. {
  108.   pass P0
  109.   {
  110.     PixelShader  = compile ps_3_0 CONVOLUTION4x4();
  111.     ZEnable = False;
  112.     FillMode = Solid;
  113.     FogEnable = False;
  114.   }
  115. };
  116.